// 04ModelLoader.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "04ModelLoader.h"
#include "stdafx.h"
#include <windows.h>
#include <mmsystem.h>
#include <TCHAR.h>
#include "h3d_pch.h"
#include "h3d_renderer.h"
#include "h3d_vertex_shader.h"
#include "h3d_pixel_shader.h"
#include "h3d_vertex_buffer.h"
#include "h3d_index_buffer.h"
#include "h3d_constant_buffer.h"
#include "h3d_source_texture.h"
#include "h3d_camera.h"
#include "h3d_vector3.h"
#include "h3d_vector4.h"
#include "h3d_light.h"
#include "h3d_sampler_state.h"
#include "h3d_obj_model_loader.h"

using namespace Heaven3D;

#define MAX_LOADSTRING 100

int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR    lpCmdLine,int       nCmdShow)
{
	H3DObjModelLoader obj_loader;
	bool ret = obj_loader.LoadFromFile(_T("spaceCompound.obj"));

	if( ret )
	{
		stringstream ss;
		ss<<"subset count = "<<obj_loader.GetSubsetCount()<<endl;

		const vector<H3DString>& texture_name_array = obj_loader.GetTextureNameArray();
		for( vector<H3DString>::const_iterator it = texture_name_array.begin() ; 
			it != texture_name_array.end(); ++it )
		{
			ss<<"texture name : "<<(*it)<<endl;
		}
/*
H3DString	mat_name_;				// 材质的颜色
H3DVector4	diffuse_color_;			// 漫反射颜色，如果有的话
int32_t		texture_array_index_;
bool		has_texture_;
bool		transparent_;
*/
		const vector<H3DObjModelMaterial>& materails = obj_loader.GetMaterials();
		for( vector<H3DObjModelMaterial>::const_iterator it = materails.begin() ; 
			it != materails.end(); ++it )
		{
			ss<<"model material : name : "<<it->mat_name_<<endl;
			ss<<"model material : diffuse color : "<<it->diffuse_color_<<endl;
			ss<<"model material : texture array index : "<<it->texture_array_index_<<endl;
			ss<<"model material : has texture : "<<(it->has_texture_ ? "TRUE" : "FALSE")<<endl;
			ss<<"model material : transparent : "<<(it->transparent_ ? "TRUE" : "FALSE")<<endl;
		}
		

		const vector<int32_t>& subset_material_array = obj_loader.GetSubsetMaterialArray();
		

		const vector<int32_t>& subset_index_start = obj_loader.GetSubsetIndexStart();
		


		MessageBox(0,ss.str().c_str(),_T("obj file information"),MB_OK );
	}
	else
	{
		MessageBox(0,_T("Can not open obj model file"),_T("obj file information"),MB_OK );
	}
	
}